package com.yunxi.controller.account;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.account.pojo.AccountTypeVO;
import com.yunxi.account.service.AccountTypeDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 帐户类型 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-16
 */
@RestController
@RequestMapping("/admin/account/accountType")
@Api(tags = "account:accountType", description = "帐户类型接口")
public class AccountTypeController {
   private static final Logger logger = LoggerFactory.getLogger(AccountTypeController.class);

   //   @Reference(version = "${demo.service.version}",
//           application = "${dubbo.application.id}",
//           url = "${dubbo.application.url}",
//           check = false,
//           timeout = 10000)
   @Autowired
   AccountTypeDubboService accountTypeDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(AccountTypeVO accountTypeVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(accountTypeDubboService.findPageByVO(accountTypeVO, pageNum, pageSize));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult listByVO(AccountTypeVO accountTypeVO) throws Exception {
      return ResponseUtil.ok(accountTypeDubboService.listByVO(accountTypeVO));
   }

   @GetMapping("/listAccountType")
   @ApiOperation(value = "查询该渠道商下可用的账户类型(一个账户类型只有一个账户)")
   public ApiResult listAccountType(AccountTypeVO accountTypeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return accountTypeDubboService.listAccountType(accountTypeVO,loginInfo);
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(AccountTypeVO accountTypeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(accountTypeDubboService.getById(accountTypeVO.getAccountTypeId()));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody List<AccountTypeVO> accountTypeVOList, @CurrentUser LoginInfo loginInfo) throws Exception {
      accountTypeDubboService.saveOrUpdate(accountTypeVOList, loginInfo);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody AccountTypeVO accountTypeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      accountTypeDubboService.removeById(accountTypeVO.getAccountTypeId(), loginInfo);
      return ResponseUtil.ok("success");
   }

   /*@GetMapping("/loadDetail")
   @ApiOperation(value = "账户类型详情")
   public ApiResult loadDetail(String accountTypeCode) throws Exception {
      return ResponseUtil.ok(accountTypeDubboService.load(accountTypeCode));
   }*/


/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(accountTypeService.findMapByList(params));
}*/
}
